package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

class SameTree {
    // 2022-08-15 10:28:04
    //leetcode submit region begin(Prohibit modification and deletion)

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     * int val;
     * TreeNode left;
     * TreeNode right;
     * TreeNode() {}
     * TreeNode(int val) { this.val = val; }
     * TreeNode(int val, TreeNode left, TreeNode right) {
     * this.val = val;
     * this.left = left;
     * this.right = right;
     * }
     * }
     */
    class Solution {
        boolean ans = true;
        public boolean isSameTree(TreeNode p, TreeNode q) {
            dfs(p, q);
            return ans;
        }

        private void dfs(TreeNode p, TreeNode q) {
            if (p == null & q == null) {
                return;
            } else if (p == null || q == null) {
                ans = false;
            } else {
                if (p.val != q.val) ans = false;
                dfs(p.left, q.left);
                dfs(p.right, q.right);
            }

        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}